package com.wwz.leetcode;

import org.junit.Test;

/**
 * 买卖股票的最佳时机 II
 */
public class LeetCode122 {


    @Test
    public void test() {
        System.out.println(maxProfit(new int[]{7, 1, 5, 3, 6, 4}));
    }

    public int maxProfit(int[] prices) {
        int ans = 0;
        for (int i = 0; i < prices.length - 1; i++) {
            // 比较连续的两个数字
            int diff = compareTwo(prices[i], prices[i + 1]);
            ans += diff;
        }
        return ans;
    }

    private int compareTwo(int price1, int price2) {
        int diff = price2 - price1;
        if (diff > 0) {
            return diff;
        }
        return 0;
    }


}
